#include "stdafx.h"
#include <iostream>
#include <time.h>
#define N 5
using namespace std;
void carica(int matr[][N], int matr1[][N]);
void trasposta(int matr[][N]);
void ordina(int matr[][N]);
void stampa(int matr[][N], int matr1[][N]);

int main()
{
	int matr[N][N];
	int matr1[N][N];
	carica(matr, matr1);
	trasposta(matr);
	ordina(matr1);
	stampa(matr, matr1);
	system("pause");
    return 0;
}
void carica(int matr[][N], int matr1[][N]) {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			matr[i][j] = 1 + rand() % (9);
			matr1[i][j] = 1 + rand() % (9);
		}
	}
}
void trasposta(int matr[][N]) {
	int temp=0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			temp = matr[j][i];
			matr[i][j] = matr[j][i];
			matr[j][i] = temp;
		}
	}
}
void ordina(int matr[][N]) {
	int temp=0;
	int c_i = 0;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = i; k < N; k++) {
				if (k == j) {
					c_i = j;
				}
				else {
					c_i = 0;
				}
				for (int v = c_i; v < N; v++) {
					if (matr[i][j] > matr[k][v]) {
						temp = matr[k][v];
						matr[k][v] = matr[i][j];
						matr[i][j] = temp;

					}
				}
			}
		}
	}

}
void stampa(int matr[][N], int matr1[][N]) {
	printf("prima matrice\n");
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			printf("%d ", matr[i][j]);
			
		}
		printf("\n");
	}
	printf("seconda matrice\n");
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			
			printf("%d ", matr1[i][j]);
		}
		printf("\n");
	}
}